<?php

namespace App\Containers\AppSection\Accreditation\Tasks;

use App\Containers\AppSection\Accreditation\Data\Repositories\RemarkRepository;
use App\Ship\Exceptions\DeleteResourceFailedException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class DeleteAllRemarksByAccreditationIdTask extends Task
{
    protected RemarkRepository $repository;

    public function __construct(RemarkRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run($accreditationId): ?int
    {
        try {
            return $this->repository->deleteWhere(['accreditation_id' => $accreditationId]);
        } catch (Exception $exception) {
            throw new DeleteResourceFailedException();
        }
    }
}
